package wtc.stu.method;

import wtc.stu.entity.StuEntity;

import java.util.List;

public class TeacherImpl implements Interface {
    @Override
    public void methodSelect() {
        System.out.println("学生信息管理系统>>>>全查询教师信息");
        System.out.println("教师编号\t教师姓名\t系别编号\t备注信息");
        List<StuEntity> ar = daoTeacher.getAll();
        for (StuEntity stuEntity : ar) {
            System.out.println(
                    "" + stuEntity.getTid() + "\t" + stuEntity.getTname() + "\t" + stuEntity.getXid() +
                            "\t" + stuEntity.getTremark() + "");
        }
        System.out.println("显示完毕 ！");
    }

    @Override
    public void methodInsert() {
        System.out.println("学生信息管理系统>>>>增加教师信息");
        System.out.println("请输入要增加的教师的所属系别：");
        System.out.println("以下是你可以选择的系别：");
        System.out.println("系别编号\t系别名称\t备注信息");
        List<StuEntity> ar = daoDepartment.getAll();
        for (StuEntity stuEntity : ar) {
            System.out.println(
                    "" + stuEntity.getXid() + "\t" + stuEntity.getXname() + "\t" + stuEntity.getXremark() + "");
        }
        System.out.println("输入系别编号即可：");
        int xid = sa.nextInt();
        System.out.println("请输入要增加的教师姓名：");
        String tname = sa.next();
        System.out.println("请输入要增加的教师备注信息：");
        String tremark = sa.next();
        // 封装
        StuEntity add = new StuEntity();
        add.setTremark(tremark);
        add.setTname(tname);
        add.setXid(xid);
        daoTeacher.addStu(add);
        System.out.println("增加成功！");
    }

    @Override
    public void methodUpdate() {
        System.out.println("学生信息管理系统>>>>全查询教师信息");
        System.out.println("教师编号\t教师姓名\t系别编号\t备注信息");
        /************ 第一步 ***************/
        List<StuEntity> ar = daoTeacher.getAll();
        for (StuEntity stuEntity : ar) {
            System.out.println(
                    "" + stuEntity.getTid() + "\t" + stuEntity.getTname() + "\t" + stuEntity.getXid() +
                            "\t" + stuEntity.getTremark() + "");
        }
        System.out.println("显示完毕 ！");
        System.out.println("以上是你可以修改的教师信息，请输入你要修改的教师的编号：");
        /************ 第二步 **************/
        int tid = sa.nextInt();
        StuEntity myTeacher = daoTeacher.getOneById(tid);
        System.out.println("请你确认以下教师信息是否是你要修改的：");
        System.out.println(
                "" + myTeacher.getTid() + "\t" + myTeacher.getTname() + "\t" + myTeacher.getXid() +
                        "\t" + myTeacher.getTremark() + "");
        /*********** 第三步 **************/
        System.out.println("请输入修改后的教师的姓名：");
        String newTname = sa.next();
        System.out.println("请输入修改后的教师所属的系别");
        int newXid = sa.nextInt();
        System.out.println("请输入要修改教师备注：");
        String newTremark = sa.next();

        StuEntity last = new StuEntity();
        last.setXid(newXid);
        last.setTremark(newTremark);
        last.setTname(newTname);
        last.setTid(tid);
        /************* 第四步 ****************/
        daoTeacher.updateStu(last);
        System.out.println("修改完毕 ！");
    }

    @Override
    public void methodDelete() {

    }
}
